<?php

/* 已测试成功
 * To change rs license header, choose License Headers in Project Properties.
 * 增加，删除，修改，成品库存
 * $statement:操作判断条件
 */
header('Content-Type: text/html; charset=utf-8');
include_once $_SERVER['DOCUMENT_ROOT'] . '/class/Product.php';
$statement = $_POST['statement'];
$product_id = $_POST['id'];
$product_model = $_POST['model'];
$product_material = $_POST['material'];
$gongyi = $_POST['gongyi'];
$number = $_POST['number'];
$product_code = $_POST['product_code'];

switch ($statement) {
    case 'add':
        echo Product::add_a_product($product_code,trim($product_model), $product_material, $gongyi, $number);
        break;

    case 'delete':

        if (Product::delete_a_product($product_id)) {
            echo 1;
        } else {
            echo 0;
        }
        break;

    case 'update';
        $rs = Product::get_Product($product_id);

        $rs->product_model = trim($product_model);
        $rs->product_material = $product_material;
        $rs->gongyi = $gongyi;
        $rs->number = $number;
        $rs->product_code = $product_code;
        if ($rs->update()) {
            echo 1;
        } else {
            echo 0;
        }
        break;
    default :
        echo 0;
        break;
}